package everyday.nowcoder;

/**
 * @Author: wenjingyuan
 * @Date: 2022/10/12/16:17
 * @Description:NC24 删除有序链表中重复的元素-II
 */
public class NumNC24 {
    /**
     *
     * @param head ListNode类
     * @return ListNode类
     */
    public ListNode deleteDuplicates (ListNode head) {
        //判空
        if(head==null){
            return  null;
        }
        //给链表加一个表头
        ListNode dummyHead=new ListNode(-1);
        dummyHead.next=head;
        ListNode cur=dummyHead;
        while(cur.next!=null && cur.next.next!=null){
            if(cur.next.val==cur.next.next.val){
                int va=cur.next.val;
                while(cur.next!=null && cur.next.val==va){
                    cur.next=cur.next.next;
                }
            }else{
                cur=cur.next;
            }
        }
        return dummyHead.next;
    }
}
